﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Mvc;
using Mapster;
using Raffles.OA.Data;
using Raffles.OA.Utility;

namespace Raffles.OA.WebApp.Areas.Manage.Controllers
{
    /// <summary>
    /// 日 期：2024-06-06 10:42:22
    /// 描 述：系统日志控制器类
    /// </summary>
    public class LogController :  BaseController<Log>
    {
        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="param"></param>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public ActionResult GetPageListJson(BaseSearchParam param, Pagination pagination)
        {
            int totalCount = 0;
            var datas = _dbContext.Queryable<Log>()
                                  .WhereIF(!param.KeyWord.IsEmpty(), x => x.MethodName.Contains(param.KeyWord) || x.ClassName.Contains(param.KeyWord) || x.OperateRealName.Contains(param.KeyWord))
                                  .OrderByDescending(x => x.CreatedOn)
                                  .ToPageList(pagination.PageIndex, pagination.PageSize, ref totalCount);
            return Content(DataResult<List<Log>>.PageResult(datas, totalCount).ToJson());
        } 

        /// <summary>
        /// 清空日志
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> LogClean()
        {
            await _dbContext.Deleteable<Log>().ExecuteCommandAsync();
            return Content(DataResult.Success().ToJson());
        }
    }
}
